<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="test1"></div>
    <div id="test2"></div>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>
    <script src="./js/prop-types.js"></script>
    <script type="text/babel">
        class Person extends React.Component {
            constructor(props) {
                console.log(props)
                super(props)
                // 如果不把props传给super那么this.props会变成未定义，但是对代码执行结果没有影响，如果你想用this.props来调用几乎用不到
                console.log(this.props)
            }
            // props类型限制
            static propTypes = {
                name: PropTypes.string.isRequired,
                sex: PropTypes.string,
                age: PropTypes.number
            }
            // 对标签初始化默认值
            static defaultProps = {
                sex:'未知',
                age:18
            }
            render() {
                // props只读，不可以修改
                const {name, age ,sex} = this.props;
                return (
                    <ul>
                        <li>姓名：{name}</li>
                        <li>性别：{sex}</li>
                        <li>年龄：{age+1}</li>
                    </ul>
                )
            }
        }
        ReactDOM.render(<Person name='wzc' />,document.getElementById("test1"))
    </script>
</body>
</html>